#define _CRT_SECURE_NO_WARNINGS

//#include"sort.h"

#include"common.h"


void test()
{
	srand((unsigned int)time(NULL));
	const int N = 20;
	int* a1 = (int*)malloc(N * sizeof(int));
	assert(a1);
	int* a2 = (int*)malloc(N * sizeof(int));
	assert(a2);
	int* a3 = (int*)malloc(N * sizeof(int));
	assert(a3);
	int* a4 = (int*)malloc(N * sizeof(int));
	assert(a4);
	int* a5 = (int*)malloc(N * sizeof(int));
	assert(a5);
	int* a6 = (int*)malloc(N * sizeof(int));
	assert(a6);
	int* a7 = (int*)malloc(N * sizeof(int));
	assert(a7); 
	int* a8 = (int*)malloc(N * sizeof(int));
	assert(a8);
	int* a9 = (int*)malloc(N * sizeof(int));
	assert(a9);
	int* a10 = (int*)malloc(N * sizeof(int));
	assert(a10);
	for (int i = 0; i < N; i++)
	{
		a1[i] = rand();
		a2[i] = a1[i];
		a3[i] = a1[i];
		a4[i] = a1[i];
		a5[i] = a1[i];
		a6[i] = a1[i];
		a7[i] = a1[i];
		a8[i] = a1[i];
		a9[i] = a1[i];
		a10[i] = a1[i];
	}

	//int begin1 = clock();
	//InsertSort(a1, N);
	//int end1 = clock();

	//int begin2 = clock();
	//ShellSort(a2, N);
	//int end2 = clock();

	//int begin3 = clock();
	//SelectSort(a3, N);
	//int end3 = clock();

	//int begin4 = clock();
	//HeapSort(a4, N);
	//int end4 = clock();

	//int begin5 = clock();
	//BubbleSort(a5, N);
	//int end5 = clock();

	int begin6 = clock();
	QuickSort(a6, 0, N - 1);
	int end6 = clock();

	int begin7 = clock();
	QuickSortNonR(a7, 0, N - 1);
	int end7 = clock();

	int begin8 = clock();
	MergeSort(a8, N);
	int end8 = clock();

	int begin9 = clock();
	MergeSortNonR(a9, N);
	int end9 = clock();

	//int begin10 = clock();
	//CountSort(a10, N);
	//int end10 = clock();

	//printf("InsertSort:%d\n", end1 - begin1);
	//printf("ShellSort:%d\n", end2 - begin2);
	//printf("SelectSort:%d\n", end3 - begin3);
	//printf("HeapSort:%d\n", end4 - begin4);
	//printf("BubbleSort:%d\n", end5 - begin5);
	printf("QuickSort:%d\n", end6 - begin6);
	printf("QuickSortNonR:%d\n", end7 - begin7);
	printf("MergeSort:%d\n", end8 - begin8);
	printf("MergeSortNonR:%d\n", end9 - begin9);
	//printf("MergeSortNonR:%d\n", end10 - begin10);


	free(a1);
	free(a2);
	free(a3);
	free(a4);
	free(a5);
	free(a6);
	free(a7);
	free(a8);
	free(a9);
	free(a10);
}

//void test1()
//{
//	int a[] = { 5,2,3,1 };
//	//SelectSort(a, 4);
//	QuickSortNonR(a, 0, 3);
//	PrintArray(a, 4);
//}

void testMerge()
{
	int a[] = { 10,6,7,1,3,9,4,2 };
	int sz = sizeof(a) / sizeof(a[0]);
	//MergeSort(a, sz);
	MergeSortNonR(a, sz);
	for (int i = 0; i < sz; i++)
	{
		printf("%d ", a[i]);
	}
	printf("\n");
}

void testCount()
{
	int a[] = { 10,6,7,1,3,9,4,2 };
	int sz = sizeof(a) / sizeof(a[0]);
	CountSort(a, sz);
	for (int i = 0; i < sz; i++)
	{
		printf("%d ", a[i]);
	}
	printf("\n");
}

void testRadix()
{
	int a[] = { 178,345,369,87,12,9,112,250,567,977,779,4,5,6,7,8,1,1,1,1,872,999,402 };
	int sz = sizeof(a) / sizeof(a[0]);
	PrintArray(a, sz);
	Radix_Sort(a, sz);
	PrintArray(a, sz);
}

int main()
{
	//test();
	//test1();
	//testMerge();
	//testCount();
	
	testRadix();


	return 0;
}